package com.hdw.auth.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hdw.auth.api.SysUseTagService;
import com.hdw.auth.bean.model.SysUseTag;
import com.hdw.auth.mapper.SysUseTagMapper;
import com.hdw.common.vo.PaginationVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * sysUseTag服务实现类
 * Created by hozeData on 2021/11/21.
 */
@Service
@Transactional
public class SysUseTagServiceImpl implements SysUseTagService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SysUseTagServiceImpl.class);

    @Autowired
    private SysUseTagMapper sysUseTagMapper;

    @Override
    public int insert(SysUseTag sysUseTag) {
        return sysUseTagMapper.insert(sysUseTag);
    }

    @Override
    public int insertSelective(SysUseTag sysUseTag)  {
        return sysUseTagMapper.insertSelective(sysUseTag);
    }

    @Override
    public int deleteById(Integer id)  {
        return sysUseTagMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByIdSelective(SysUseTag sysUseTag)  {

        return sysUseTagMapper.updateByPrimaryKeySelective(sysUseTag);
    }

    @Override
    public int updateById(SysUseTag sysUseTag)  {
        return sysUseTagMapper.updateByPrimaryKey(sysUseTag);
    }

    @Override
    public SysUseTag getById(Integer id)  {
        return sysUseTagMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysUseTag> findByModel(SysUseTag sysUseTag)  {
        return sysUseTagMapper.findByModel(sysUseTag);
    }

    @Override
    public PaginationVO<SysUseTag> findPageByModel(SysUseTag sysUseTag, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<SysUseTag> quesList = sysUseTagMapper.findByModel(sysUseTag);
        PageInfo<SysUseTag> pageInfo = new PageInfo<>(quesList);
        PaginationVO<SysUseTag> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public List<Map<String, Object>> findByUseId(Integer useId) {
        return sysUseTagMapper.findByUseId(useId);
    }

    @Override
    public int delete(Integer userId, Integer tagId) {
        return sysUseTagMapper.delete(userId,tagId);
    }
}
